Skip to content

fix: handle punkt_tab fallback in split_sentences for NLTK >= 3.9 - #1023

Open
danishashko wants to merge 2 commits into
codelucas:masterfrom
danishashko:fix/punkt-tab-fallback
Open

fix: handle punkt_tab fallback in split_sentences for NLTK >= 3.9#1023
danishashko wants to merge 2 commits into
codelucas:masterfrom
danishashko:fix/punkt-tab-fallback

Conversation

@danishashko

Copy link
Copy Markdown

Fixes #1017

NLTK 3.9 moved the default punkt tokenizer from tokenizers/punkt/english.pickle to tokenizers/punkt_tab/english. On a fresh install with NLTK >= 3.9 only punkt_tab is downloaded, so calling split_sentences() raises a LookupError even when NLTK is properly installed.

What this changes:

  1. newspaper/nlp.py - split_sentences() now tries the old path first and falls back to punkt_tab if not found. Works with both old and new NLTK versions.
  2. download_corpora.py - adds punkt_tab to REQUIRED_CORPORA so it gets downloaded alongside punkt.

PR #1006 already adds punkt_tab to the download list, but the runtime crash in nlp.py still happens if only punkt_tab is available. This fixes both.

dc-harsh added a commit to dc-harsh/newspaper that referenced this pull request May 29, 2026
- requirements: add lxml-html-clean (fixes `import newspaper` breaking on lxml>=5)
- nlp: NLTK punkt_tab fallback in split_sentences (codelucas#1023) + collapse
  intra-sentence newlines (codelucas#873); download_corpora adds punkt_tab (codelucas#1023)
- cleaners: itemprop contains("articleBody") keeps multi-token itemprop nodes (codelucas#953)
- extractors: include <article> in scoring candidate nodes (codelucas#865)
- tests: expect precise meta article:published_time (intended fork behavior)
- bump version to 0.4.0

@pgwimberl71 pgwimberl71 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1f6e1770c95468d862d86084d290aa8b0e8b5db71f6e1770c95468d862d86084d290aa8b0e8b5db7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WordTokenizer conflict with nltk >= 3.8.2

2 participants